package com.yswee.mallnavi.activity.common;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import com.yswee.framework.utils.StringUtils;
import com.yswee.framework.utils.ViewInject;
import com.yswee.framework.widget.loading.LoadingWebView;
import com.yswee.mallnavi.R;
import com.yswee.mallnavi.activity.base.BaseActivity;

public class AIServiceActivity extends BaseActivity {

    public static final String INTENT_URL = "url";

    @ViewInject
    private LoadingWebView uvwebview;
    @ViewInject
    private View imgclose;

    private String mUrl;

    @Override
    protected boolean isDialogTheme() {
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aiservice);
    }

    @Override
    protected void onQueryArguments(Intent intent) {
        super.onQueryArguments(intent);
        mUrl = intent.getStringExtra(INTENT_URL);
        if (StringUtils.isEmpty(mUrl)) {
            showToastMessage(R.string.error_param);
            finish();
        }
    }

    @Override
    protected void onBindListener() {
        super.onBindListener();
        imgclose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void onApplyData() {
        super.onApplyData();
        uvwebview.setHideProgressBar(true);
        uvwebview.loadUrl(mUrl);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(uvwebview.onKeyDown(keyCode, event)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(uvwebview != null) {
            uvwebview.destroy();
        }
    }
}